<!--
 * @Author: zhangweinan
 * @Date: 2022-12-06 20:04:56
 * @LastEditors: zhangweinan
 * @LastEditTime: 2022-12-06 20:05:03
 * @Description: file content
 * @FilePath: \front-end-of-task-center\src\views\enterprise\NodeForm.vue
-->
<template>
  <div class="node-form-wrap">
    <Parser
      :key="new Date().getTime()"
      :form-conf="detailForm"
      @change="handleChange"
      :hasConfirmBtn="false"
    />
  </div>
</template>

<script>
import { decodeFields } from "@/utils/formGenerator";
import Parser from "@/components/parser/Parser";

import { getNodeFormJson } from "@/api/bpm/task.js";

export default {
  name: "NodeForm",
  components: {
    Parser,
  },
  props: ["task"],
  data() {
    return {
      detailForm: {
        fields: [],
      },
    };
  },
  // watch: {
  //   detailForm: {
  //     handler(val) {
  //       this.$emit('change', val)
  //     },

  //   }
  // },
  created() {
    const query = {
      taskId: this.task.id,
      // userId: this.$store.getters.userId
    };
    getNodeFormJson(query).then((res) => {
      if (!res.data) return;
      this.detailForm = {
        ...JSON.parse(res.data.conf),
        fields: decodeFields(res.data.fields),
      };
    });
  },
  methods: {
    handleChange(val) {
      this.$emit("change", val);
    },
  },
};
</script>

<style scoped lang="scss"></style>
